package com.zxmc.server.controller.user;

import com.zxmc.common.context.BaseContext;
import com.zxmc.common.result.Result;
import com.zxmc.pojo.entity.ReadingHistory;
import com.zxmc.pojo.vo.ReadingHistoryVO;
import com.zxmc.server.service.ReadingHistoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/readingHistory")
@Slf4j
@Api(tags = "阅读历史相关接口")
public class ReadingHistoryController {
    @Autowired
    private ReadingHistoryService readingHistoryService;
    @ApiOperation("用户浏览历史查询(单本小说)")
    @GetMapping("/list")
    public Result<ReadingHistory> list(Integer id) {
        log.info("用户浏览历史查询list,{}",id);
        return Result.success(readingHistoryService.list(id));
    }
    @ApiOperation("用户浏览历史查询(某用户全部小说)")
    @GetMapping("/listAll")
    public Result<List<ReadingHistoryVO>> listAll(Integer id) {
        log.info("用户浏览历史查询listAll,{}", id);
        return Result.success(readingHistoryService.listAll(id));
    }
    @ApiOperation("用户浏览历史插入")
    @PostMapping("/insert")
    public Result insert(String key,@RequestBody ReadingHistory readingHistory) {
        log.info("insert,{}",readingHistory);
        readingHistoryService.insert(key,readingHistory);
        return Result.success();
    }

    @ApiOperation("用户浏览历史更新")
    @PostMapping("/update")
    public Result update(@RequestBody ReadingHistory readingHistory) {
        log.info("update,{}",readingHistory);
        readingHistoryService.update(readingHistory);
        return Result.success();
    }
    
}
